﻿using JT.WEB.Service;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NewsPublish.Model.Response;

namespace JTWEB3.Areas.Admin.Controllers
{
    [Area("Admin")]
    public class CommentController : Controller
    {
        private readonly CommentService _commentService;
        public CommentController(CommentService commentService)
        {
            _commentService = commentService;
        }
        // GET: Comment
        public IActionResult Index()
        {
            return View(_commentService.GetCommentList(c => true));
        }

        // GET: Comment/Details/5
        public ActionResult Details()
        {
            return View();
        }

        // GET: Comment/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: Comment/Create
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }

        // GET: Comment/Edit/5
        public ActionResult Edit()
        {
            return View();
        }

        // POST: Comment/Edit/5
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(int id, IFormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }

        // GET: Comment/Delete/5
        //public JsonResult DelComment(int id)
        //{
        //    return View();
        //}

        // POST: Comment/Delete/5
        [HttpPost]
        //[ValidateAntiForgeryToken]
        public JsonResult DelComment(int id)
        {
            if (id <= 0)
                return Json(new ResponseModel { code = 0, result = "评论不存在" });
            return Json(_commentService.DeleteComment(id));
        }
    }
}